from typing import List
from itertools import product


class Solution:
    def isValidSudoku(self, board: List[List[str]]) -> bool:
        # Rule 1, 2
        for i in range(9):
            line = board[i]
            col = [board[j][i] for j in range(9)]
            for num in range(1, 10):
                if line.count(str(num)) > 1:
                    return False
                if col.count(str(num)) > 1:
                    return False
        # Rule 3
        for i, j in product(range(3), range(3)):
            lines = [line[j*3:(j+1)*3] for line in board[i*3:(i+1)*3]]
            nums = []
            for line in lines:
                nums.extend(line)
            for num in range(1, 10):
                if nums.count(str(num)) > 1:
                    return False
        return True


if __name__ == "__main__":
    s = Solution()
    print(s.isValidSudoku(board = 
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]))
